package org.web.common.sso.client.helper;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.web.base.domain.ResultDO;
import org.web.common.sso.client.biz.impl.PropertiesConstantInterface;
import org.web.common.sso.client.domain.SessionAccountDO;

public class SSOHelper {

    public static SessionAccountDO getSessionAccountDO() {
        return (SessionAccountDO) RequestContextHolder.getRequestAttributes().getAttribute(PropertiesConstantInterface.SESSION_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
    }

    public static void setSessionAccountDO(SessionAccountDO sessionAccountDO) {
        RequestContextHolder.getRequestAttributes().setAttribute(PropertiesConstantInterface.SESSION_ATTRIBUTE_NAME, sessionAccountDO, RequestAttributes.SCOPE_REQUEST);
    }

    public static ResultDO<SessionAccountDO> generateSessionAccountByStr(String str) {
        Gson gson = new Gson();
        return gson.fromJson(str, new TypeToken<ResultDO<SessionAccountDO>>() {
        }.getType());
    }
}